package com.kdzy.lshy.socity_server.controller;

import com.kdzy.lshy.socity_server.common.RequestConver;
import com.kdzy.lshy.socity_server.service.DwellerMessageService;
import io.swagger.annotations.*;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 居民消息入口
 * @author cly
 * @since 2018-06-21
 */
@RestController
@RequestMapping("/dwMessage")
@CrossOrigin("*")
@Api(value = "DwellerMessageController", description = "居民消息入口")
public class DwellerMessageController {

    private static final Logger logger = LoggerFactory.getLogger(DwellerMessageController.class);

    @Resource
    private DwellerMessageService dwellerMessageService;

    /**
     * 居民我的消息 -- 列表查询
     * @param param 包含消息内容
     * @return 结果集
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(notes = "/list", httpMethod = "POST", value = "居民我的消息 -- 列表查询", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "成功"),
            @ApiResponse(code = 1, message = "结果集为空"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
            @ApiResponse(code = 33, message = "systoken过期"),
            @ApiResponse(code = 331, message = "systoken不一致")
    })
    public Object list(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产,\n" +
                            " \"type\": 消息类型 0:短信 1:微信 2:站内,\n" +
                            " \"content\": \"消息内容\",\n" +
                            " \"read_type\": 阅读状态 0:未读 1:已读,\n" +
                            " \"systoken\": \"(当visit_plat = 0时)全局token\"\n" +
                            "}")
            String param, HttpServletRequest request){
        logger.info("进入《居民我的消息 -- 列表查询》list()方法；入参param = " + param);
        return dwellerMessageService.getAllByCondition(param, RequestConver.getRequestPayload(request));
    }

    /**
     * 居民我的消息 -- 消息删除
     * @param param 消息Id
     * @return 是否成功
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ApiOperation(notes = "/del", httpMethod = "POST", value = "居民我的消息 -- 消息删除", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "数据更新成功"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
            @ApiResponse(code = 33, message = "systoken过期"),
            @ApiResponse(code = 331, message = "systoken不一致")
    })
    public Object delMessage(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"ID\": \"消息唯一标识\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产,\n" +
                            " \"systoken\": \"(当visit_plat = 0时)全局token\"\n" +
                            "}")
            String param, HttpServletRequest request){
        logger.info("进入《居民我的消息 -- 消息删除》del()方法；入参param = " + param);
        return dwellerMessageService.delete(param, request);
    }

    /**
     * 居民我的消息 -- 消息更新
     * @param param 消息id
     * @return 是否成功
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(notes = "/update", httpMethod = "POST", value = "居民我的消息 -- 消息更新", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "数据更新成功"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
            @ApiResponse(code = 33, message = "systoken过期"),
            @ApiResponse(code = 331, message = "systoken不一致")
    })
    public Object updateMessage(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"ID\": \"消息唯一标识\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产,\n" +
                            " \"content\": \"更新内容\",\n" +
                            " \"systoken\": \"(当visit_plat = 0时)全局token\"\n" +
                            "}")
            String param, HttpServletRequest request){
        logger.info("进入《居民我的消息 -- 消息更新》updateMessage()方法；入参param = " + param);
        return dwellerMessageService.update(param, request);
    }

}
